<template>
  <div class="stat">
		<iframe class="flowStatClass" width="100%" height="100%" :src="linkAddr"></iframe>
  </div>
</template>

<script>
import { getMenuInfo } from 'utils'

export default {
  computed: {
    linkAddr () {
      const menuName = this.$route.params.name
      if (!menuName) {
        return
      }

      const menuInfo = getMenuInfo(menuName)
      if (!menuInfo) {
        return
      }

      let url = menuInfo.path

      if (url.startsWith('http')) {
        return url
      }

      if (url.charAt(0) !== '/') {
        url = `/${url}`
      }

      return window.contextPath + url
    }
  },
  methods: {
    resizeWindow(){
      let resizeTimer = null;
      $(window).bind('resize', function (){
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function(){
          console.log("页面改变")
          var clientHeight = document.documentElement.clientHeight
          // TODO: iframe高度计算
          var iframeHeight = clientHeight - 64 - 15 -47;
          $(".flowStatClass").height(iframeHeight)
        } , 100);
      });
    },
    initIframeHeight(){
      // TODO: iframe高度计算
      var clientHeight = document.documentElement.clientHeight
      var iframeHeight = clientHeight - 64 - 15 -47;
      $(".flowStatClass").height(iframeHeight)
    }
  },
  mounted() {
    this.$nextTick(()=> {
      this.initIframeHeight()
    })
    this.resizeWindow()
  }
}
</script>

<style scoped>
  .flowStatClass{
    border: none
  }
</style>
